<?php

/**
 * Created by PhpStorm.
 * User: Simpson
 * Date: 2016/11/10
 * Time: 15:57
 */
namespace App\Transformer;

use League\Fractal\Manager;
use League\Fractal\Resource\Collection;
class RepairTransformer
{
    protected $manager;

    public function __construct(Manager $manager)
    {
        $this->manager = $manager;
    }


    /**
     * 格式化预约信息
     *
     * @param $arrays
     * @return array
     */
    public function order($arrays)
    {
        $resource = new Collection($arrays, function (array $array){
            return [
                'id' => $array['order_id'],
                'name' => $array['user']['name'],
                'number' => $array['user']['number'],
                'gender' => $array['user']['gender'],
                'dormitory_address' => $array['user']['dormitory_address'],
                'cellphone' => $array['user']['cellphone'],
                'short_phone' => $array['user']['short_phone'],
                'schedule' => $array['content'],
                'platform' => $array['platform'],
                'description' => $array['description'],
                'status' => $array['status'],
                'order_time' => $array['order_time'],
                'created_at' => $array['order_created_at']
            ];
        });

        return $this->manager->createData($resource)->toArray();
    }

    /**
     * 格式化任务信息
     *
     * @param $arrays
     * @return array
     */
    public function task($arrays)
    {
        $resource = new Collection($arrays, function (array $array){
            return [
                'id' => $array['order_id'],
                'user' => [
                    'name' => $array['user']['name'],
                    'number' => $array['user']['number'],
                    'gender' => $array['user']['gender'],
                    'dormitory_address' => $array['user']['dormitory_address'],
                    'cellphone' => $array['user']['cellphone'],
                    'short_phone' => $array['user']['short_phone'],
                ],
                'operator' => [
                    'name' => $array['operator']['user']['name'],
                    'number' => $array['operator']['number'],
                    'cellphone' => $array['operator']['user']['cellphone'],
                    'short_phone' => $array['operator']['user']['short_phone'],
                ],
                'schedule' => $array['content'],
                'platform' => $array['platform'],
                'description' => $array['description'],
                'status' => $array['status'],
                'order_time' => $array['order_time'],
                'created_at' => $array['order_created_at']
            ];
        });

        return $this->manager->createData($resource)->toArray();
    }


    /**
     * 格式化维护人员信息
     *
     * @param $arrays
     * @return array
     */
    public function operator($arrays)
    {
        $resource = new Collection($arrays, function (array $array){
            return [
                'id' => $array['id'],
                'number' => $array['number'],
                'name' => $array['user']['name'],
                'cellphone' => $array['user']['cellphone'],
                'short_phone' => $array['user']['short_phone'],
                'gender' => $array['user']['gender'],
            ];
        });

        return $this->manager->createData($resource)->toArray();
    }

    /**
     * 格式化rank信息
     *
     * @param $arrays
     * @return array
     */
    public function rank($arrays)
    {
        $resource = new Collection($arrays, function (array $array){
            return [
                'id' => $array['id'],
                'name' => $array['user']['name'],
                'number' => $array['number'],
                'repair_count' => $array['repair_count'],
            ];
        });

        return $this->manager->createData($resource)->toArray();
    }
}